/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import com.mysql.jdbc.PreparedStatement;
import dto.Categoria;
import dto.Link;
import factory.daoUtil;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.spi.DirStateFactory.Result;

/**
 *
 * @author victor
 */
public class Categorias implements generics.GenericoDao<Categoria> {

    public List<Categoria> select() {
        List<Categoria> retorno = null;
        String sql = "SELECT * FROM blogdb.categoria";

        try {

            PreparedStatement ps = (PreparedStatement) daoUtil.getInstance().getPrepareStatemen(sql);
            ResultSet rs = ps.executeQuery();

            retorno = new ArrayList<Categoria>();

            while (rs.next()) {

                Categoria categOb = new Categoria();

                

                categOb.setId(rs.getInt("id"));
                categOb.setDescricao(rs.getString("descricao"));
                categOb.setDataCriacao(rs.getDate("data_criacao"));
                categOb.setFlag(rs.getBoolean("flag"));
                categOb.setIcon(rs.getString("icon"));


                retorno.add(categOb);
            }

        } catch (Exception ex) {
            Logger.getLogger(Links.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            daoUtil.getInstance().fecharTudo();
        }



        return retorno;
    }

public boolean insert(Categoria ob) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public boolean edit(Categoria ob) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    public Categoria view(Categoria ob) {
        Categoria catOb = new Categoria();
        
        String sql = "SELECT * FROM blogdb.categoria WHERE id = ?";
        
        try {
            try {
                
                PreparedStatement ps = (PreparedStatement) daoUtil.getInstance().getPrepareStatemen(sql);
                ps.setInt(1, ob.getId());
                
                ResultSet rs = ps.executeQuery();
                
                while (rs.next()) {
                    catOb.setId(rs.getInt("id"));
                    catOb.setIcon(rs.getString("icon"));
                    catOb.setDataCriacao(rs.getDate("data_criacao"));
                    catOb.setDescricao(rs.getString("descricao"));
                    catOb.setFlag(rs.getBoolean("flag"));
                

}
                
            } catch (Exception ex) {
                Logger.getLogger(Categorias.class  

.getName()).log(Level.SEVERE, null, ex);
            }
        } finally {
            daoUtil.getInstance().fecharTudo();
        }
        
        return catOb;
    }
    
    public boolean delete(Categoria ob) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    

}
